<!-- src/views/user/AclList.vue -->
<script setup>
import { ref, onMounted, watch } from 'vue';
import { useAclStore } from '@/stores/aclStore.js';
import BaseTable from '@/components/table/BaseTable.vue';
import AclEdit from '@/views/user/AclEdit.vue';
import AclDetail from '@/views/user/AclDetail.vue';
import AclAdd from "@/views/user/AclAdd.vue";
const aclStore = useAclStore();
const tableData = ref([]);
const aclEditRef = ref(null);
const aclDetailRef = ref(null); // 添加详情组件引用
const aclAddRef = ref(null);

onMounted(() => {
  aclStore.getAclList();
});

watch(
    () => aclStore.aclList,
    (newVal) => {
      tableData.value = newVal;
    },
    { deep: true }
);
// 查看详情
const handleDetail = (aclInfo) => {
  aclDetailRef.value.show(aclInfo);
};


const handleEdit = (aclInfo) => {
  aclEditRef.value.show(aclInfo);
};

const handleDelete = (id) => {
  aclStore.deleteAcl(id);
};

const handleCurrentChange = (val) => {
  aclStore.pageInfo.pageNum = val;
  aclStore.getAclList();
};

const handleAdd = () => {
  aclAddRef.value.show();
};
</script>

<template>
  <div>
    <div style="margin-bottom: 15px;">
      <el-button type="primary" @click="handleAdd">新增权限</el-button>
    </div>

    <el-table :data="tableData" border>
      <el-table-column label="权限名称" prop="name"></el-table-column>
      <el-table-column label="权限代码" prop="code"></el-table-column>
      <el-table-column label="类型" prop="type"></el-table-column>
      <el-table-column label="资源路径" prop="url"></el-table-column>
      <el-table-column label="操作">
        <template v-slot="scope">
          <el-button type="primary" size="small" @click="handleEdit(scope.row)">编辑</el-button>
          <el-button type="danger" size="small" @click="handleDelete(scope.row.id)">删除</el-button>
          <el-button type="info" size="small" @click="handleDetail(scope.row)">查看</el-button>
        </template>
      </el-table-column>
    </el-table>

    <el-pagination
        :total="aclStore.pageInfo.total"
        :page-size="aclStore.pageInfo.pageSize"
        :current-page="aclStore.pageInfo.pageNum"
        @current-change="handleCurrentChange"
        layout="total, prev, pager, next"
        style="margin-top: 20px; text-align: right;"
    />

    <AclEdit ref="aclEditRef"/>
    <AclDetail ref="aclDetailRef"/>
    <AclAdd ref="aclAddRef"/>

  </div>
</template>

<style scoped>
</style>
